<template>
  <div class="goodsList">
    <!--<mt-header title="商品列表" fixed>-->
      <!--<router-link to="/show" slot="left">-->
        <!--<mt-button icon="back"></mt-button>-->
      <!--</router-link>-->
    <!--</mt-header>-->
    <Vheader title="商品列表"></Vheader>
    <section class="main">
      <nav class="list_nav">
        <ul class="nav">
          <li @click="sort('total',1)" :class="{ active: isActive == 'total'}">
            <span>综合</span><span></span></li>
          <li @click="sort('count',1)" :class="{ active: isActive == 'count'}">
            <span>销量</span>
            <span :class="{ upred: ud == 'count',downred:ud == 'countdown',updown:ud != 'countdown'}"></span>
          </li>
          <li @click="sort('price',1)" :class="{ active: isActive == 'price'}">
            <span>价格</span>
            <span :class="{ upred: ud == 'price',downred:ud == 'pricedown',updown:ud != 'pricedown'}"></span>
          </li>
          <li @click="sort('create_time',1)" :class="{ active: isActive == 'create_time'}">
            <span>最新</span><span></span></li>
        </ul>
      </nav>
      <section class="listBox" v-cloak>
        <scroll class="list-wrapper" :data="list" :probeType="probeType" :pullup="pullup" @pullup="allSort">
          <div class="list-container">
            <ul class="content">
              <a @click="details(goods.product_id)" v-for="goods in list">
                <div class="imgBox">
                  <img :src="goods.image | jsonImgShow" alt="">
                </div>
                <div class="titleBox">
                  <p><b>{{goods.price}}</b><span>￥{{goods.price/goods.discount}}</span></p>
                  <p class="showTitle">{{goods.product_name}}</p>
                </div>
              </a>
              <div class="loading-hook"></div>
            </ul>
          </div>
        </scroll>
      </section>
    </section>
  </div>
</template>

<script>
  import axios from '../../axios/axios'
  import BScroll from 'better-scroll';
  import scroll from '../../components/scroll'
  import Vheader from '../../components/header'
  export default {
    name: 'goodsList',
    data() {
      return {
        pullup:true,
        probeType:3,
        list: [],
        newlist:[],
        id: '',
        isActive: '',
        flag: true,
        updown: 'desc',
        ud: '',
        namesort:'total',
        page:1,
        searchName:'',
      }
    },
    components: {
      scroll,Vheader
    },
    mounted: function () {
      this.id = this.$route.query.id;
      this.searchName=this.$route.query.searchName;
      console.log(this.id,this.searchName);
      this.sort('total',1);
    },
    methods: {
      allSort:function () {
        this.page++;
        console.log('hhhhhh');
         var bottomTip=document.querySelector('.loading-hook');
        if (this.newlist.length === 0) {
           bottomTip.innerText = '无数据';
          console.log('11');
          this.pullup=false
        } else {
          this.sort(this.namesort,2);
          console.log('222');
           bottomTip.innerText = '加载更多';
        }
      },
      sort: function (sortname,p) {
        var that = this;
        if(p==1){
          that.list=[];
          that.page=1;
        }
        that.namesort=sortname;
        that.ud = '';
        that.isActive = sortname;
        if (sortname == 'price' || sortname == 'count') {
          if (that.updown == 'desc') {
            that.ud = sortname
            that.updown = 'asc'
          } else {
            that.ud = sortname + 'down'
            that.updown = 'desc'
          }
        }
        // console.log(that.updown)
        if(this.id){
          var data = JSON.stringify({
            "actionName": "queryListPage",
            "controllerName": "productInfo",
            "data": [{
              // "good": true,
              "groupId": that.id,
              "orderBy": that.updown,
              // "productName": "",
              "sortName": sortname,
              // "top": false
            },
              that.page,
              6]
          });
        }else if(this.searchName){
          var data = JSON.stringify({
            "actionName": "queryListPage",
            "controllerName": "productInfo",
            "data": [{
              // "good": true,
              // "groupId": that.id,
              "orderBy": that.updown,
              "productName": this.searchName,
              "sortName": sortname,
              // "top": false
            },
              that.page,
              6]
          });
        }

        axios.post({
          data: data,
          callback(res) {
            that.newlist=res.data.data;
            console.log('aaaa');
            console.log(that.newlist);
            that.list=that.list.concat(res.data.data)
          }
        })
      },
      details: function (id) {
        var that = this;
        that.$router.push({path: '/details', query: {id: id}});
      }
    }
  }
</script>
<style type="text/scss" lang="scss" scoped>
  @import "../../common/style/public";
  .exit {
    width: 90%;
    margin-left: 5%;
    margin-top: 20vw;
  }

  .main {
    .list_nav {
      height: 36px;
      background-color: #fff;
      width: 100%;
      position: fixed;
      top: 45px;
      left: 0;
      z-index: 99;
      border-top: solid 1px #f5f5f5;
      ul {
        display: flex;
        justify-content: space-around;
        width: 100%;
        height: 100%;
        line-height: 36px;
        font-size: 12px;
        li {
          text-align: center;
          .updown {
            display: inline-block;
            width: 0;
            height: 0;
            border-left: 4px solid transparent;
            border-right: 4px solid transparent;
            border-bottom: 6px solid gray;
            margin-left: 4px;
          }
          .upred {
            display: inline-block;
            width: 0;
            height: 0;
            border-left: 4px solid transparent;
            border-right: 4px solid transparent;
            border-bottom: 6px solid red;
            margin-left: 4px;
          }
          .downred {
            display: inline-block;
            width: 0;
            height: 0;
            border-left: 4px solid transparent;
            border-right: 4px solid transparent;
            border-top: 6px solid red;
            margin-left: 4px;
          }
        }
        li.active {
          color: red;
          border-bottom: solid 1px red;
        }
      }
    }
  }

  .listBox {
    .list-wrapper {
      width: 100%;
      height: calc(100% - 85px);
      position: absolute;
      top: 85px;
      overflow: hidden;
      .list-container {
        width: 100%;
      }
    }
    ul {
      display: flex;
      flex-wrap: wrap;
      justify-content: space-between;
      a {
        width: 49%;
        height: 60vw;
        background-color: #fff;
        /*margin-top: 2px;*/
        margin-bottom: 2%;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        /*border:0.5vw solid #e3e3e3;*/
        .imgBox {
          height: 66%;
          width: 100%;
          img {
            width: 100%;
            height: 100%;
          }
        }
        .titleBox {
          height: 34%;
          padding: 4px 6px 0 6px;
          p {
            font-size: 12px;
            b {
              color: red;
              font-size: 18px;
              font-weight: 100;
            }
            span {
              text-decoration: line-through;
              font-size: 12px;
              color: gray;
              margin-left: 6px;
            }
          }
          .showTitle {
            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 2;
          }
        }
      }
    }
  }

  [v-cloak] {
    display: none;
  }

  /*.active{*/
  /*color: red;*/
  /*}*/
</style>







